<template>
  <div class="widget-group">
    <div class="group-title">容器组件
      <el-icon>
        <Grid />
      </el-icon>
    </div>
    <draggable class="component-list" :list="designer.containerWidgetList"
      :group="{ name: 'form', pull: 'clone', put: false }"
      :clone="(componet) => designer.cloneComponent(componet, widgetList)" item-key="id">
      <template #item="{ element }">
        <div class="component-item">{{ element.label }}</div>
      </template>
    </draggable>

    <div class="group-title">表单组件
      <el-icon>
        <Edit />
      </el-icon>
    </div>
    <draggable class="component-list" :list="designer.itemWidgetList"
      :group="{ name: 'form', pull: 'clone', put: false }"
      :clone="(componet) => designer.cloneComponent(componet, widgetList)" item-key="id">
      <template #item="{ element }">
        <div class="component-item">{{ element.label }}</div>
      </template>
    </draggable>

    <div class="group-title">基础组件
      <el-icon>
        <Notification />
      </el-icon>
    </div>
    <draggable class="component-list" :list="designer.basicComponentList"
      :group="{ name: 'form', pull: 'clone', put: false }"
      :clone="(componet) => designer.cloneComponent(componet, widgetList)" item-key="id">
      <template #item="{ element }">
        <div class="component-item">{{ element.label }}</div>
      </template>
    </draggable>

    <div class="group-title" v-if="customWidgetList.length != 0">自定义组件
      <el-icon>
        <User />
      </el-icon>
    </div>
    <draggable class="component-list" :list="customWidgetList" :isFormItem="true"
      :group="{ name: 'form', pull: 'clone', put: false }"
      :clone="(componet) => designer.cloneComponent(componet, widgetList)" item-key="id">
      <template #item="{ element }">
        <div class="component-item">{{ element.label }}</div>
      </template>
    </draggable>
  </div>
</template>

<script setup>
import { inject } from 'vue'
import { Grid, Edit, Notification, User } from '@element-plus/icons-vue'
// 注入 designer
const designer = inject('designer')
const widgetList = inject('widgetList')
const customWidgetList = inject('customWidgetList')

</script>

<style scoped>
.widget-group {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  padding: 10px;
  box-sizing: border-box;
  background: var(--el-fill-color-light);
  border-radius: 12px;
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.widget-group::-webkit-scrollbar {
  display: none;
}

.group-title {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 5px;
  font-size: 14px;
  font-weight: 600;
  color: var(--el-color-primary);
  margin: 5px 5px 10px 5px;
}

.component-list {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  margin-bottom: 24px;
}

.component-item {
  margin-top: 10px;
  margin-left: 6px;
  margin-right: 6px;
  padding: 8px 10px;
  background-color: var(--el-bg-color);
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05); 
  font-size: 13px;
  text-align: center;
  cursor: grab;
  transition: transform 0.2s, box-shadow 0.2s;
}

.component-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}
</style>